/****************************************************************************
**
** This file is part of qPhotoTag, a photo keywording application
**
** Copyright (C) 2009 Marcell Lengyel <miketkf@gmail.com>
**
** GNU General Public License
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**
****************************************************************************/

#ifndef __PHOTOVIEW_H__
#define __PHOTOVIEW_H__
/*! \file photoview.h
    \brief Contains the declaration of the PhotoView class

    The PhotoView class is used for displaying the photo thumbnails in a
    grid view
 */
#include <QListView>
#include <QStandardItemModel>
#include "photo.h"

#define ICON_GRID_HEIGHT    160     // The height of the thumbnail grid
#define ICON_GRID_WIDTH     148     // The width of the thumbnail grid
#define ICON_HEIGHT         144     // The maximum height of a thumbnail
#define ICON_WIDTH          144     // The maximum witdth of a thumbnail

//! A widget for displaying photo thumbnails in a grid
/*!
  This is a QListView subclass with a ViewMode set to QListView::IconMode
  It is used for displaying thumbnails of photos, adds a small globe icon
  on top of the photo thumbnail if the photo contains GPS coordinates in
  the EXIF data and displays a dialog with a larger picture if the thumbnail
  of a photo is double clicked.
 */
class PhotoView : public QListView
{
    Q_OBJECT
public:
    //! Constructor
    /*!
      Constructor for the PhotoView widget, a subclass of QListView.
      It sets the basic layout and properties.
     */
    PhotoView(QWidget *parent = 0);
    //! Destructor
    /*!
      The destructor deletes the resources that were allocated in the Constructor.
     */
    ~PhotoView();

protected:
    //! Event handler override for key press events
    /*!
      This event handler captures the Delete key press and removes the currently
      selected thumbnails from the view. It also emits the photoViewDeletePressed()
      signal.

      \param event a pointer to a QKeyEvent
     */
    void keyPressEvent(QKeyEvent *event);

signals:
    //! The signal is emitted when the Delete key is pressed
    /*!
      \sa keyPressEvent()
     */
    void photoViewDeletePressed();
public:
    //! A method for checking if any items are selected from the list
    /*!
      This method can be used to check if there are any keywords selected from the
      keyword list.

      \return true if item(s) are selected
     */
    bool is_selection();
    //! Adds a new photo to the thumbnail view
    /*!
      This method is used for adding new photos to the thumbnail view. The PhotoView
      class also maintains a list with the EXIF and IPTC data for the photos in the
      thumbnail view. new_file is responsible for creating a new Photo::Photo class
      (which manages the EXIF and IPTC data) and adding it to the list.
      For the thumbnail creation it uses the EXIF thumbnail (if available) or scales
      the original image to the correct size. It also adds the globe icon to the
      thumbnail if the photo already contains GPS information.

      \param full_path a QString with the absolute path to the photo to be added
     */
    void new_file(const QString &full_path);
    //! Returns a list of all keywords found in all the photos
    /*!
      This method returns a sorted QStringList that contains all the IPTC keywords
      for all the photos in the thumbnail view.

      \return the list of all IPTC keywords
     */
    QStringList get_tag_list();
    //! Returns a list of all keywords found in the selected photos
    /*!
      This method returns a sorted QStringList that contains all the IPTC keywords
      for the selected photos in the thumbnail view.

      \return the list of IPTC keywords for the selected photos
     */
    QStringList get_selected_tag_list();
    //! Returns the IPTC caption tag for the selected photos
    /*!
      This method return a single QString with the caption text for the selected
      photos, taken from the IPTC Caption tag. If the caption is different for the
      selected photos then it returns [Multiple values].

      \return a caption text
     */
    QString get_selected_caption();
    //! Adds a caption text to the selected photos
    /*!
      This method sets a new value to the IPTC Caption tag for the selected photos.

      \param new_caption a QString with the caption value to be set
     */
    void add_caption_to_selected(const QString &new_caption);
    //! Checks if the thumbnail view is empty
    /*!
      This method checks if the thumbnail view is empty or not.

      \return true if there are no thumbnails in the view
     */
    bool isEmpty();
    //! Adds a new IPTC keyword to the selected photo(s)
    /*!
      This method adds a single keyword to the IPTC keywords list of the selected
      photo(s).

      \param new_tag a QString keyword to be added to the IPTC keywords
     */
    void add_tag_to_selected(const QString &new_tag);
    //! Adds new IPTC keywords to the selected photo(s)
    /*!
      This method appends the list of keywords to the selected photo(s). It
      checks if there is a selection and the list is not empty.

      \param new_tag_list a list of IPTC keywords to be added
     */
    void add_tags_to_selected(const QStringList &new_tag_list);
    //! Removes IPTC keywords from the selected photo(s)
    /*!
      This method removes the list of IPTC keywords from the selected photos.
      It checks if there is a selection and that the list is not empty.

      \param old_tag_list a list of IPTC keywords to be removed
     */
    void remove_tags_from_selected(const QStringList &old_tag_list);
    //! Saves the modified EXIF and IPTC data back to the photos
    /*!
      This method walks through all the photos in the view and initiates a
      save action on them.

      \sa Photo::save_all()
     */    
    void save_exif_data();
    //! Updates the GPS coordinates in the selected photos
    /*!
      This method loops through the slected photos, removes the possibly existing
      GPS coordinates from the IPTC keywords and adds the new ones. It also sets the
      GPS coordinates to the EXIF data.

      \param lat is the Latitude value
      \param lon is the Longutide value
      \param alt is the Altitude value
     */
    void update_gps_coordinates_to_selected(const double lat, const double lon, const double alt);

    //! Displays a picture in a dialog window
    /*!
      This method is called when a thumbnail is double clicked. It figures
      out the absolute path of the photo and displays a downscaled copy in a
      separate dialog window.

      \param index an identifier of the double clicked photo
     */
    void display_picture_dialog(const QModelIndex &index);
	
    void get_lens_data_for_selected(QString &model, Qt::CheckState &model_update,
                                    double &max_aperture, Qt::CheckState &max_aperture_update,
                                    double &fnumber, Qt::CheckState &fnumber_update,
                                    double &focallength, Qt::CheckState &focallength_update);
    void set_lens_data_for_selected(QString model, Qt::CheckState model_update,
                                    double max_aperture, Qt::CheckState max_aperture_update,
                                    double fnumber, Qt::CheckState fnumber_update,
                                    double focallength, Qt::CheckState focallength_update);
private:
    //! Not implemented yet
    void add_globe(int row);
    //QModelIndexList get_selected_items();
    //! Removes the selected thumbnails from the view
    /*!
      This method is called when the delete key is pressed and there are
      selected thumbnails in the view.
      First it displays a question dialog and if the action is confirmed
      the thumbnails are removed.
     */
    void remove_selected_items();
    //! Returns the filename part of an absolute path
    /*!
      This method strips the path component of an absolute path and returns
      the file name.

      \param fullFileName an absolute path to an image file
      \return a QString with the file name part of the path
     */
    QString strippedName(const QString &fullFileName);
    //! Model to store the thumbnails
    /*!
      It is a model for a listview for storing an icon and a text
      (thumbnail and filename).
     */
    QStandardItemModel *model;
    //! A list for storing EXIF and IPTC data
    /*!
      It is a list that contains a Photo::Photo class for each thumbnail which
      contains an absolute path to the photo, EXIF and IPTC data, etc.
     */
    QList<Photo*> photo_list;
    //! A globe icon for marking the geotagged photos
    /*!
      This is a pixmap for storing the small globe icon that is overlayed
      on the thumbnails that contain GPS location information in their
      EXIF headers.
     */
    QPixmap *globe;
};
	
#endif // __PHOTOVIEW_H__
